package Learn;


import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;

import myio.StringOps;
import mymath.ArrayComparator;

import rcaller.RCaller;
import rcaller.RCode;

import Data.datamanager;


public class clusterer {
	

	public static void main(String[] args){
		
		Configuration config = new Configuration(args[0]);
		
		String rinputdata = config.datamatrix();
		String rcodehome = config.rcodehome();
		int layerstruc[] = config.layerstruc(); 
		String layerstructype[] = config.layerstructype();
		
		
		/* Creating a RCaller */
	    RCaller caller = new RCaller();
	    caller.setRscriptExecutable(config.rscript());
	   
	    /* Creating a source code */
	    RCode code = new RCode();
	    code.clear();
	    
	    /* defining the input */
	    code.addRCode("inputdata =  ");
	    code.addRCode(" '" + rinputdata + "'");
	    
	    
	    /* basename for output files */
	    
	    String outputhome = config.outputhome();
	    
	    Calendar mycal = new GregorianCalendar();
		SimpleDateFormat mydateform = new SimpleDateFormat("dd.MM.yyyy'-'HH:mm:ss");
		String timestamp = mydateform.format(mycal.getTime());
		String basename = outputhome + "clusterout_"+ timestamp ;
		
		System.out.println(basename);
		code.addRCode("outputbase =  ");
	    //code.addRCode(basename + "; ");
	    code.addRCode("'"+basename+"';");
	    code.addRCode("layerstruc = ");
	    code.addRCode("c" + StringOps.arrayToString(layerstruc,"(",")")   );
	    code.addRCode("layerstructype = ");
	    code.addRCode("c" + StringOps.arrayToQuotedString(layerstructype,"(",")")   );
	    code.addRCode("maxit <-" + config.maxit() + ";");
	    code.addRCode("source('" + rcodehome + "makerandomclus.r');");
	    code.addRCode("source('" + rcodehome + "savexml.r');");
	    code.addRCode("source('" + rcodehome + "jclustermain.r');");
	    
	    caller.setRCode(code);
	    caller.redirectROutputToConsole();
	    caller.runOnly();
	    

	  } /* end main */

}
